package com.zany.util.file;


import com.zany.util.ZanyErrorMsg;
import com.zany.util.ZanyException;
import com.zany.util.cache.CacheManageSupport;
import com.zany.util.cache.SCache;
import com.zany.util.xml.SystemXML;

public final class SCacheManage {

    private SystemXML sysXML;
    private static String  fileName="base.xml";
    private static SCacheManage cacheManage;
     static{
         try{
           cacheManage=new SCacheManage();
         }catch(ZanyException e){
            System.out.println(e.getMessage());

         }
    }
    public static SCacheManage getInstance()throws ZanyException{
        if(cacheManage==null){
           try{
              cacheManage=new SCacheManage();
           }catch(ZanyException e){
            throw new ZanyException(ZanyErrorMsg.FILE_ERROR,"系统配置文件错误");
           }
        }
         return cacheManage;
    }
    private SCacheManage()throws ZanyException {
        sysXML=new SystemXML();
        init();
    }
    /**
     * xml装载，如果系统xml文件需要动态刷新可调用该方法
     * @throws ZanyException
     */
    public void init()throws ZanyException{
    	CacheManageSupport support=new CacheManageSupport();
    	support.init(fileName,false,sysXML);
    }
    /**
     * xml装载，如果系统xml文件需要动态刷新可调用该方法
     * @throws ZanyException
     */
	public void refresh()throws ZanyException{
        CacheManageSupport support=new CacheManageSupport();
        support.init(fileName,false,sysXML);
	}
    /**
     * 系统缓存获取
     * @return SCache
     */
	public  SCache getSCache(){
    	return sysXML.getSCache();
	}
	public String getValue(String parent,String child)throws ZanyException{
		String str= (String)sysXML.getSCache().getChildMap(parent).get(child);
		if(str==null)str="";
		return str;
   
	}

}
